package IViews;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JPanel;
import javax.swing.JTextPane;

public class IAlert extends JPanel {

	private MouseAdapter doNOthing = new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent e) {
			// Do nothing, verhindert einen click auf hinter liegende felder....
		}
	};
	
	private IImageWraper[] border;
	private JPanel con;
	
	public IAlert(int width, int height, String pTypeText, String pText, JPanel parent) {
		
		border = new IImageWraper[9];
		con = new JPanel();
		int x = (parent.getWidth()/2)-(width/2);
		int y = (parent.getHeight()/2)-(height/2);
		con.setBounds(x, y, width, height);
		con.setOpaque(false);
		con.setLayout(null);
		
		
		this.setBounds(0, 0, parent.getWidth(), parent.getHeight());
		this.setOpaque(false);
		this.setLayout(null);
		
		//oben
		border[0] = new IImageWraper(0, 0, 17, 17, "Borders/alert_corner_0.png");
		border[1] = new IImageWraper(17, 0, width - 34, 17, "Borders/alert_border_1.png");
		border[2] = new IImageWraper(width - 17, 0, 17, 17,
				"Borders/alert_corner_1.png");
		//unten
		border[3] = new IImageWraper(0, height-23, 17, 23,
				"Borders/alert_corner_3.png");
		border[4] = new IImageWraper(17, height-23, width-34, 23,
				"Borders/alert_border_3.png");
		border[5] = new IImageWraper(width-17, height-23, 17, 23,
				"Borders/alert_corner_2.png");
		
		//linker rand
		border[6] = new IImageWraper(0, 17, 17, height-40, "Borders/alert_border_0.png");
		//rechter rand
		border[7] = new IImageWraper(width-17, 17, 17, height-40, "Borders/alert_border_2.png");
		
		//feld hintergrund
		border[8] = new IImageWraper(17, 17, width-34, height-40, "Borders/alert_background.png");
		
		//background-gray
		IImageWraper im = new IImageWraper(0, 0, parent.getWidth(), y, "Borders/alertFiller.png");
		im.addMouseListener(doNOthing);
		this.add(im);
		im = new IImageWraper(0, y+height, parent.getWidth(), parent.getHeight()-y-height, "Borders/alertFiller.png");
		im.addMouseListener(doNOthing);
		this.add(im);
		im = new IImageWraper(0, y, x, height, "Borders/alertFiller.png");
		im.addMouseListener(doNOthing);
		this.add(im);
		im = new IImageWraper(x+width, y, parent.getWidth()-x-width, height, "Borders/alertFiller.png");
		im.addMouseListener(doNOthing);
		this.add(im);
		
		for (int i = 0; i < border.length; i++) {
			if (border[i] != null) {
				con.add(border[i]);
			}
		}
		con.addMouseListener(doNOthing);
		this.add(con, 0);
		parent.setOpaque(true);
		
		
		//Disable all fields behind
		System.out.println(parent.getClass().getName());
		Component[] c = parent.getComponents();
		for (int i = 0; i < c.length; i++) {
			if(c[i] instanceof ITableView){
				((ITableView) c[i]).setAllEnabled(false);
			}
		}
		
	}
	
}
